package com.shycloud.mido.task.service.impl;

import com.shycloud.mido.common.core.exception.BusinessException;
import com.shycloud.mido.common.security.util.SecurityUtils;
import com.shycloud.mido.task.api.vo.NoticeVO;
import com.shycloud.mido.task.mapper.BasicGoodsInfoMapper;
import com.shycloud.mido.task.reward.RewardAbstract;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shycloud.mido.task.api.entity.SmMemberNotice;
import com.shycloud.mido.task.mapper.SmMemberNoticeMapper;
import com.shycloud.mido.task.service.SmMemberNoticeService;

@Service
@AllArgsConstructor
public class SmMemberNoticeServiceImpl extends ServiceImpl<SmMemberNoticeMapper, SmMemberNotice> implements SmMemberNoticeService {

	/** 通知公告模块 mapper */
	private SmMemberNoticeMapper noticeMapper;

	private final Map<String, RewardAbstract> rewardTypeMap;

	@Override
	public List<NoticeVO> getNotice(String memberId, String type) {
		return noticeMapper.getNotice(memberId, type);
	}

	@Override
	public boolean receiveReward(Integer orgId, Integer id) {

		SmMemberNotice notice = noticeMapper.selectById(id);

		if (notice == null) {
			throw new BusinessException("未找到对应通知信息，请确认传入的 id 是否正确");
		}

		//领取奖励 START
		boolean res = rewardTypeMap.get(notice.getRewardType()).getReward(orgId, SecurityUtils.getMember().getId(), notice.getRewardGoodsId());

		if (res) {
			//修改状态为【已领取】
			noticeMapper.updateStatus(SecurityUtils.getMember().getId());
		}

		return true;
	}
}
